package com.wontube.smr.web.pub;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
 * @author tanggf(2012-5-15)
 *
 */
public class PageCacheResponseWrapper extends HttpServletResponseWrapper{
	private ByteArrayOutputStream byteOutput;
	private PrintWriter writer;

	public PageCacheResponseWrapper(HttpServletResponse response) {
		super(response);		
	}
	
	public byte[] getDataAsBytes(){
		return byteOutput.toByteArray();
	}
	
	@Override
	public PrintWriter getWriter() throws IOException {	
		if(writer == null){
			byteOutput = new ByteArrayOutputStream();
			writer = new PrintWriter(byteOutput);
		}
		return writer;
	}
	
}
